$(document).ready(function(){
//	获取当前url参数
	$.getQueryString=function(paraname){
		var reg = new RegExp("(^|&)" + paraname + "=([^&]*)(&|$)","i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r!=null){
	        return (r[2]);
	    }
	    return null;
	}
	var id = $.getQueryString("id");
	console.log("id:"+id);
	getSentimentDetail(id);
})


//来源分类图
function chart1(ratio){
	var chart = {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            };
	var title = {
		text: '来源分类'
	};
	var tooltip = {
		pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	};
	var plotOptions = {
		pie: {
			allowPointSelect: true,
			cursor: 'pointer',
			dataLabels: {
				enabled: true,
				format: '<b>{point.name}</b>: {point.percentage:.1f} %',
				style: {
					color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
				}
			}
		}
	};
	console.log(ratio);
	var media_arr = new Array();
	for (var i = 0; i < ratio.length; i++) {
		media_arr[i] = {};
		media_arr[i].name = ratio[i].source;
		media_arr[i].y = ratio[i].ratio;
	}
	var series= [{
		type: 'pie',
		name: 'Browser share',
		data: [
			['微博',   500],
			['豆瓣',       400],
			['论坛',    300],
			{
				name: '新闻门户',
				y: 600,
				sliced: true,
				selected: true
			},
			['微信',     100],
		]
	}];

	var json = {};
	json.chart = chart;
	json.title = title;
	json.tooltip = tooltip;
	json.series = series;
	json.plotOptions = plotOptions;
	$('#mediaRatio').highcharts(json);
	
}
	//时间评论量变化图
function chart2(ratio){
	var chart = {
		type: 'column'
	};
	var title = {
		text: '时间/评论量变化'
	};

	var xAxis = {
		categories: ['新浪微博','豆瓣','人民网','搜狐','雅虎','网易','凤凰网'],
		crosshair: true
	};
	var yAxis = {
		min: 0,
		title: {
			text: '量 (条)'
		}
	};
	var tooltip = {
		headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
		pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
		'<td style="padding:0"><b>{point.y:.1f} 条</b></td></tr>',
		footerFormat: '</table>',
		shared: true,
		useHTML: true
	};
	var plotOptions = {
		column: {
			pointPadding: 0.2,
			borderWidth: 0
		}
	};
	var credits = {
		enabled: false
	};

	var series= [{
		name: '评论量',
		data: [65,59,90,81,56,55,40]
	}, {
		name: '转发量',
		data: [28,44,40,19,96,27,100]
	}];

	var json = {};
	json.chart = chart;
	json.title = title;
	json.tooltip = tooltip;
	json.xAxis = xAxis;
	json.yAxis = yAxis;
	json.series = series;
	json.plotOptions = plotOptions;
	json.credits = credits;
	$('#reprintRatio').highcharts(json);
	
}

//时间/舆情导向变化
function chart3(ratio){
	

    $('#sentimentRatio').highcharts({
        title: {
            text: '时间/舆情导向变化',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: 临沂一村民强拆中被烧死',
            x: -20
        },
        xAxis: {
            categories: ['9.14', '9.15', '9.16', '9.17', '9.18', '9.19','9.20', '9.21', '9.22', '9.23', '9.24', '9.25']
        },
        yAxis: {
			max: 1,
			min: 0,
            title: {
                text: '舆情导向'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: '舆情导向',
            data: [-20, -40, -50, -55, -45, -45, -43, -37, -30, -28, -28, -28]
        }, ]
    });
}
//时间/转载量变化
function chart4(ratio){
    $('#pageViewRatio').highcharts({
        title: {
            text: '时间/转载量变化',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: 临沂一村民强拆中被烧死',
            x: -20
        },
        xAxis: {
            categories: ['9.14', '9.15', '9.16', '9.17', '9.18', '9.19','9.20', '9.21', '9.22', '9.23', '9.24', '9.25']
        },
        yAxis: {
			min: 0,
            title: {
                text: '舆情导向'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: '访问量',
            data: [4500, 8300,10200, 10700, 11000, 11100, 11200, 11250, 11270, 11280, 11299, 12007]
        }, ]
    });
}
function getSentimentDetail(id){
	$.ajax({
		type:"get",
		url:'../../HotSentimentServlet?method=getHotspotReportById',
		data:{
			"id":id
		},
		success:function(data){
			console.log(data);
			var commentGraph = JSON.parse(data).commentGraph;
			var reprintGraph = JSON.parse(data).reprintGraph;
			var sentimentGraph =JSON.parse(data).sentimentGraph;
			chart2(commentGraph);
			chart4(reprintGraph);
			chart3(sentimentGraph);
		    var title = $("<h3 class=\"contentTitle\">【热点舆情】" + JSON.parse(data).title + "</h3>");
		    $("#sentimenttitle").append(title);
		    
		    var time = $("<p>" + JSON.parse(data).beginDate  + "-" +  JSON.parse(data).endDate + "</p>");
		    $("#monitortime").append(time);
		    
		    $.each(JSON.parse(data).text,function(index,value){
		    	var content = $("<p style=\"font-weight: 400\" class=\"text-justify\">&nbsp;&nbsp;&nbsp;&nbsp;" + this+ "</p>");
		    	$("#reportcontent").append(content);
		    });
		    
		    var explain = $("<p style=\"font-weight: 500\">样本数据来源于网络舆情监测系统&nbsp;&nbsp;取样截止时间：" + JSON.parse(data).endDate + "</p>");
		    $("#explain").append(explain);
		    
		    var opinionlist = JSON.parse(data).opinion;
		    $.each(opinionlist,function(index,value){
	    		 var opinion = $("<p style='font-weight: 400' class='text-justify'>&nbsp;&nbsp;&nbsp;&nbsp;<strong>"+this.split("：")[0]+"：</strong>"+this.split("：")[1]+"</p>");
	    		 
	    		 $("#opinionlist").append(opinion);
	    	 });
		      
		},
		error:function(){
			console.log("error");
		}
	});
}
